<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<?php
    // header("Content-type: application/octet-stream");
    // header("Content-Disposition: attachment; filename=laporan.xls");
    // header("Pragma: no-cache");
    // header("Expires: 0");
?>

<style type="text/css">
<!--
body,td,th {
	font-size: 13px;
	font-family:Arial,Helvetica;
	vertical-align:middle;
}
.judul{	
	font-size:30px;
	font-weight: bold;
	text-align:center;
} 

.subjudul{	
	font-size:18px;
	text-align:center;
	font-weight: bold;
} 

.headertabel {
	font-size:16px;
	text-align:center;
	background-color:#BFBFBF;
	border-width: 1px;
	border-style:solid;
}

.isi_tabel
{
    border-width: 1px 1px 1px 1px;
	border-style:solid;
	font-size:16px;
}

.lain
{
	font-weight: bold;
	font-size:20px;
	
}
-->
</style>

<?
//set nama bulan
$bulan_num = date('m');
if($bulan_num == 1){
	$bulan_awal = 'Jan';
	$bulan_akhir = 'Feb';
}
else if($bulan_num == 2){
	$bulan_awal = 'Feb';
	$bulan_akhir = 'Maret';
}
else if($bulan_num == 3){
	$bulan_awal = 'Maret';
	$bulan_akhir = 'April';
}
else if($bulan_num == 4){
	$bulan_awal = 'April';
	$bulan_akhir = 'Mei';
}
else if($bulan_num == 5){
	$bulan_awal = 'Mei';
	$bulan_akhir = 'Juni';
}
else if($bulan_num == 6){
	$bulan_awal = 'Juni';
	$bulan_akhir = 'Juli';
}
else if($bulan_num == 7){
	$bulan_awal = 'Juli';
	$bulan_akhir = 'Agst';
}
else if($bulan_num == 8){
	$bulan_awal = 'Agst';
	$bulan_akhir = 'Sept';
}
else if($bulan_num == 9){
	$bulan_awal = 'Sept';
	$bulan_akhir = 'Okt';
}
else if($bulan_num == 10){
	$bulan_awal = 'Okt';
	$bulan_akhir = 'Nov';
}
else if($bulan_num == 11){
	$bulan_awal = 'Nov';
	$bulan_akhir = 'Des';
}
else if($bulan_num == 12){
	$bulan_awal = 'Des';
	$bulan_akhir = 'Jan';
}


	$hitung_keping = $this->db->query("SELECT count(ID_KEPING_SEGMEN) as total FROM keping_jalan_segmen where NO_RUAS = ".$this->session->userdata('no_ruas')."");
	foreach ($hitung_keping->result() as $rows) {
		$jumlah_keping = $rows->total;
	}
	
	$margercell = 6+$jumlah_keping;
  

?>
<table border="0" cellspacing="0">
  
  <tr>
    <td width="515" colspan="<?=$margercell?>" class="subjudul">
		Strip Map Ruas jalan Nasional Berdasarkan ketidakrataan Permukaan Jalan (IRI)</br>
		Direktorat Jenderal Bina Marga
    </td>
  </tr>
  
  <tr>
	<td width="515" colspan="<?=$margercell?>">&nbsp;</td>
  </tr>
  <tr>
	<td width="515" colspan="<?=$margercell?>"><b>Status Data : <?=$this->session->userdata('nama_periode')?></b></td>
  </tr>
  <tr>
	<td width="515" colspan="<?=$margercell?>">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td align="center">Keterangan :</td>
	<td>&nbsp;</td>
    <td bgcolor="#009900" align="center"><b>Baik</b></td>
    <td>&nbsp;</td>
    <td bgcolor="#FFFF00" align="center"><b>Sedang</b></td>
    <td>&nbsp;</td>
    <td bgcolor="#FF6600" align="center"><b>Rusak Ringan</b></td>
    <td>&nbsp;</td>
    <td bgcolor="#FF0000" align="center"><b>Rusak Berat</b></td>
    <td colspan="<?=$jumlah_keping-4;?>">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td align="center">&nbsp;</td>
	<td>&nbsp;</td>
    <td align="center"><b>A = ASPAL</b></td>
    <td>&nbsp;</td>
    <td align="center"><b>P = PENMAC</b></td>
    <td>&nbsp;</td>
    <td align="center"><b>T = TANAH</b></td>
    <td>&nbsp;</td>
    <td align="center">&nbsp;</td>
    <td colspan="<?=$jumlah_keping-4;?>">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td colspan="2">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td colspan="<?=$jumlah_keping;?>">&nbsp;</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td colspan="2">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td colspan="<?=$jumlah_keping?>">&nbsp;</td>
  </tr>
  
  
  <tr>
    <td rowspan="" class="headertabel">No</td>
    <td rowspan="" class="headertabel">No Ruas</td>
    <td colspan="2" rowspan="" class="headertabel">Nama Ruas</td>
    <td rowspan="" class="headertabel">Panjang</td>
    <td rowspan="" class="headertabel">Keterangan</td>
    <td colspan="<?=$jumlah_keping?>" class="headertabel">Nilai IRI Pada Posisi Segment Ruas Jalan Per-100 Meter</td>
	</tr>
	
	<tr>
		<td rowspan="7" class="isi_tabel">&nbsp;</td>
		<td rowspan="7" align="center" class="isi_tabel"><?=$no_ruas?></td>
		<td colspan="2" align="center" class="isi_tabel">GPS Awal</td>
		<td rowspan="7" class="isi_tabel" align="center"><?=$panjang_jalan?></td>
		<td class="isi_tabel">Nilai IRI</td>
	<?
		$no = 1;
		foreach ($data_keping->result() as $row){
			$warna = '';
			if($row->NILAI_IRI >= 0 && $row->NILAI_IRI < 4){
				$warna = '#009900';
			}
			else if($row->NILAI_IRI >= 4 && $row->NILAI_IRI < 8){
				$warna = '#FFFF00';
			}
			else if($row->NILAI_IRI >= 8 && $row->NILAI_IRI < 12){
				$warna = '#FF6600';
			}
			else $warna = '#FF0000';
			echo '
				<td class="isi_tabel" bgcolor="'.$warna.'" align="center" width="80px">'.$row->NILAI_IRI.'</td>
				';
			$no++;
		}
	?>
	</tr>
	
	<tr>
		<td width="100px" align="center" class="isi_tabel">Longitude</td>
		<td width="100px" align="center" class="isi_tabel">Latitude</td>
		<td class="isi_tabel">Posisi KM</td>
	<?
		$no = 1;
		foreach ($data_keping->result() as $row){
			echo '
				<td class="isi_tabel" align="center" width="80px">'.$row->POSISI_KM.'</td>
				';
			$no++;
		}
	?>
	</tr>
	
	<tr>
		<td align="center" class="isi_tabel"><?=$gps_awal_lat?></td>
		<td align="center" class="isi_tabel"><?=$gps_awal_long?></td>
		<td class="isi_tabel">Panjang (km)</td>
	<?
		$no = 1;
		foreach ($data_keping->result() as $row){
			echo '
				<td class="isi_tabel" align="center" width="80px">0.1</td>
				';
			$no++;
		}
	?>
	</tr>
	
	<tr>
	  <td colspan="2" class="isi_tabel" align="center"><?=$nama_ruas_jalan?></td>
		<td class="isi_tabel">Tipe</td>
	<?
		$no = 1;
		foreach ($data_keping->result() as $row){
			echo '
				<td class="isi_tabel" align="center" width="80px">'.$row->TIPE.'</td>
				';
			$no++;
		}
	?>
	</tr>
	
	<tr>
		<td colspan="2" class="isi_tabel" align="center">GPS Akhir</td>
		<td class="isi_tabel">Lebar Jalan</td>
	<?
		$no = 1;
		foreach ($data_keping->result() as $row){
			echo '
				<td class="isi_tabel" align="center" width="80px">'.$row->LEBAR.'</td>
				';
			$no++;
		}
	?>
	</tr>
	
	<tr>
		<td class="isi_tabel" align="center">Longitude</td>
		<td class="isi_tabel" align="center">Latitude</td>
		<td class="isi_tabel">Total (km)</td>
		<td bgcolor="#009900" class="isi_tabel" align="center"><?=$tot_km_hijau?></td>
		<td bgcolor="#FFFF00" class="isi_tabel" align="center"><?=$tot_km_kuning?></td>
		<td bgcolor="#FF6600" class="isi_tabel" align="center"><?=$tot_km_orange?></td>
		<td bgcolor="#FF0000" class="isi_tabel" align="center"><?=$tot_km_merah?></td>
	</tr>
	
	<tr>
		<td class="isi_tabel" align="center"><?=$gps_akhir_lat?></td>
		<td class="isi_tabel" align="center"><?=$gps_akhir_long?></td>
		<td class="isi_tabel">Total (%)</td>
		<?$tot_all_km = $tot_km_hijau+$tot_km_kuning+$tot_km_orange+$tot_km_merah;?>
		<td bgcolor="#009900" class="isi_tabel" align="center"><?=substr($tot_km_hijau/$tot_all_km*100, 0,6)?> %</td>
		<td bgcolor="#FFFF00" class="isi_tabel" align="center"><?=substr($tot_km_kuning/$tot_all_km*100, 0,6)?> %</td>
		<td bgcolor="#FF6600" class="isi_tabel" align="center"><?=substr($tot_km_orange/$tot_all_km*100, 0,6)?> %</td>
		<td bgcolor="#FF0000" class="isi_tabel" align="center"><?=substr($tot_km_merah/$tot_all_km*100, 0,6)?> %</td>
	</tr>
	
    <tr>
		<td width="515" colspan="<?=$margercell?>">&nbsp;</td>
	</tr>
	<tr>
		<td width="515" colspan="<?=$margercell?>">&nbsp;</td>
	</tr>
	<tr>
		<td width="515" colspan="<?=$margercell?>">&nbsp;</td>
	</tr>
	
	  <?
		
				$tahun = 2012;
				// $tahun_awal = 2012;
				// $tahun_ahir = 2013;
		$tahun_awal2 = $tahun_awal;
		while ($tahun_awal <= $tahun_ahir){
		echo'
		<tr>
		<td>&nbsp;</td>
		<td>&nbsp;</td>		
		<td class="isi_tabel" colspan="4">PENANGANAN TAHUN '.$tahun_awal.'</td>
		
		';
		foreach ($data_keping->result() as $row){
				$get_penanganan = $this->db->query("SELECT * FROM penanganan_segmen where TAHUN = ".$tahun_awal." AND ID_KEPING_SEGMEN = ".$row->ID_KEPING_SEGMEN." ORDER BY ID_KEPING_SEGMEN ASC	");
				// echo '<tr>';
					// if($get_penanganan == null){
							// echo '<td class="isi_tabel" align="center" width="80px">&nbsp;</td>';
						// }
					// else{
						$penanganan_counter = 0;
						
						foreach ($get_penanganan->result() as $rows){
								$penanganan = $rows->PENANGANAN;
								echo '
									<td class="isi_tabel" align="center" width="80px">'.$penanganan.'</td>
								';
								$penanganan_counter = 1;
							
								
						}
						
						//echo '</tr>';
						
						
						// if($penanganan_counter < $margercell){
							// echo '
								// <td class="isi_tabel" align="center" width="80px">-</td>
								// ';
						// }
					//}
				
			
			$tahun++;
		}
		echo '</tr>';
		
		//print alokasi penanganan
		echo'
		<tr>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td class="isi_tabel" colspan="4">ALOKASI PENANGANAN</td>
		
		';
		foreach ($data_keping->result() as $row){
				$get_penanganan = $this->db->query("SELECT * FROM penanganan_segmen where TAHUN = ".$tahun_awal." AND ID_KEPING_SEGMEN = ".$row->ID_KEPING_SEGMEN." ORDER BY ID_KEPING_SEGMEN ASC	");
				// echo '<tr>';
					// if($get_penanganan == null){
							// echo '<td class="isi_tabel" align="center" width="80px">&nbsp;</td>';
						// }
					// else{
						$penanganan_counter = 0;
						
						foreach ($get_penanganan->result() as $rows){						
								echo '
									<td class="isi_tabel" align="center" width="80px">'.$rows->ALOKASI.'</td>
								';
								$penanganan_counter = 1;
							
								
						}
						
						//echo '</tr>';
						
						
						// if($penanganan_counter < $margercell){
							// echo '
								// <td class="isi_tabel" align="center" width="80px">-</td>
								// ';
						// }
					//}
				
			
			$tahun++;
		}
		echo '</tr>';
		
		
		//cetak prediksi kondisi
		echo'
		<tr>
		<td>&nbsp;</td>
		<td>&nbsp;</td>
		<td class="isi_tabel" colspan="4">PREDIKSI KONDISI AKHIR '.$tahun_awal.'</td>
		
		';
		foreach ($data_keping->result() as $row){
				$get_penanganan = $this->db->query("SELECT * FROM penanganan_segmen where TAHUN = ".$tahun_awal." AND ID_KEPING_SEGMEN = ".$row->ID_KEPING_SEGMEN." ORDER BY ID_KEPING_SEGMEN ASC	");
				// echo '<tr>';
					// if($get_penanganan == null){
							// echo '<td class="isi_tabel" align="center" width="80px">&nbsp;</td>';
						// }
					// else{
						$penanganan_counter = 0;
						
						foreach ($get_penanganan->result() as $rows){						
							if($rows->PENANGANAN == '-'){
								//$prediksi = 'Merah';
								if($row->NILAI_IRI >= 0 && $row->NILAI_IRI < 4){
									$prediksi = '#009900';
								}
								else if($row->NILAI_IRI >= 4 && $row->NILAI_IRI < 8){
									$prediksi = '#FFFF00';
								}
								else if($row->NILAI_IRI >= 8 && $row->NILAI_IRI < 12){
									$prediksi = '#FF6600';
								}
								else $prediksi = '#FF0000';
							}
							else $prediksi = '#009900';
							echo '
								<td class="isi_tabel" align="center" width="80px" bgcolor="'.$prediksi.'">&nbsp;</td>
							';
							$penanganan_counter = 1;
							
								
						}
						
						//echo '</tr>';
						
						
						// if($penanganan_counter < $margercell){
							// echo '
								// <td class="isi_tabel" align="center" width="80px">-</td>
								// ';
						// }
					//}
				
			
			$tahun++;
		}
		echo '</tr>';
		
		$tahun_awal++;
		
		
		//cetak jarak
		echo '
		<tr>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<tdcolspan="'.$jumlah_keping.'">&nbsp;</td>
		</tr>
		';
		}//end of loop
		
		
		//cetak rekap tabel kondisi jalan
		echo '
		<tr>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<tdcolspan="'.$jumlah_keping.'">&nbsp;</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<tdcolspan="'.$jumlah_keping.'">&nbsp;</td>
		</tr>
		';
		echo '
		<tr>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td colspan="2"><b>TABEL KONDISI JALAN</br></td>
			<tdcolspan="'.$jumlah_keping.'">&nbsp;</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<tdcolspan="'.$jumlah_keping.'">&nbsp;</td>
		</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				<td class="isi_tabel">&nbsp;</td>
				';
				$tahun_awal3=$tahun_awal2;
				$tahun_awal4=$tahun_awal3;
				$tahun_awal5=$tahun_awal4;
				while ($tahun_awal3 <= $tahun_ahir){
				echo'
				<td class="isi_tabel" colspan="4" align="center">KONDISI AKHIR TA. '.$tahun_awal3.'</td>
				';
				$tahun_awal3++;
				}
				echo'
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				<td class="isi_tabel">&nbsp;</td>
				';
		while ($tahun_awal2 <= $tahun_ahir){
		echo'
				<td class="isi_tabel" align="center">BAIK</td>
				<td class="isi_tabel" align="center">SEDANG</td>
				<td class="isi_tabel" align="center">R. RINGAN</td>
				<td class="isi_tabel" align="center">R. BERAT</td>
			';
			$tahun_awal2++;
			
		}
		
		
		echo'
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				<td class="isi_tabel">KM</td>
				';
		while ($tahun_awal4 <= $tahun_ahir){
		echo'
				<td class="isi_tabel" align="center">'.$tot_km_hijau.'</td>
				<td class="isi_tabel" align="center">'.$tot_km_kuning.'</td>
				<td class="isi_tabel" align="center">'.$tot_km_orange.'</td>
				<td class="isi_tabel" align="center">'.$tot_km_merah.'</td>
				
			';
			$tahun_awal4++;
			
		}
		
		
		echo'
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				<td class="isi_tabel">%</td>
				';
		while ($tahun_awal5 <= $tahun_ahir){
		echo'
				<td class="isi_tabel" align="center">'.substr($tot_km_hijau/$tot_all_km*100, 0,6).' %</td>
				<td class="isi_tabel" align="center">'.substr($tot_km_kuning/$tot_all_km*100, 0,6).' %</td>
				<td class="isi_tabel" align="center">'.substr($tot_km_orange/$tot_all_km*100, 0,6).' %</td>
				<td class="isi_tabel" align="center">'.substr($tot_km_merah/$tot_all_km*100, 0,6).' %</td>
				
			';
			$tahun_awal5++;
			
		}
		echo '</tr>';
		
		
		echo'
		<tr>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<tdcolspan="'.$jumlah_keping.'">&nbsp;</td>
		</tr>
		';
		echo '
		<tr>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<tdcolspan="'.$jumlah_keping.'">&nbsp;</td>
		</tr>
		';
		echo '
		<tr>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<tdcolspan="'.$jumlah_keping.'">&nbsp;</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td colspan="2"><b>ALOKASI KEBUTUHAN TA</br></td>
			<tdcolspan="'.$jumlah_keping.'">&nbsp;</td>
		</tr>
		<tr align="center">
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td class="isi_tabel">JENIS PENANGANAN</td>
			<td class="isi_tabel">SATUAN</td>
			<td class="isi_tabel">VOLUME</td>
			<td class="isi_tabel">ALOKASI DANA</br>(dalam juta rupiah)</td>
		</tr>
		<tr align="center">
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td class="isi_tabel">RUTIN JALAN</td>
			<td class="isi_tabel">Km</td>
			<td class="isi_tabel">12</td>
			<td class="isi_tabel">12</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<tdcolspan="'.$jumlah_keping.'">&nbsp;</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<tdcolspan="'.$jumlah_keping.'">&nbsp;</td>
		</tr>
		<tr>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<tdcolspan="'.$jumlah_keping.'">&nbsp;</td>
		</tr>
		';
		
	?>
</table>
